<template>
  <div class="page-container">
    <div class="info-container_header">
      <svg class="icon" @click="handleCancel" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4136">
        <path
          d="M499.498667 225.834667a42.666667 42.666667 0 0 1 0 60.330666L316.330667 469.333333H810.666667a42.666667 42.666667 0 1 1 0 85.333334H316.330667l183.168 183.168a42.666667 42.666667 0 1 1-60.330667 60.330666l-256-256a42.666667 42.666667 0 0 1 0-60.330666l256-256a42.666667 42.666667 0 0 1 60.330667 0z"
          p-id="4137"
        />
      </svg>

      <div class="title">活动详情</div>
    </div>
    <div class="info-container">
      <div class="info-container_body">
        <el-form ref="refFrom" label-position="top" class="demo">
          <div class="form-section">
            <div class="form-section_title">活动摘要</div>

            <Abstract ref="abstract" :data="currentItem"></Abstract>
          </div>
          <div class="form-section">
            <div class="form-section_title">活动参与详情列表</div>
            <Join ref="join" :data="currentItem"></Join>
          </div>
          <div class="form-section">
            <div class="form-section_title">定向投放日志</div>
            <Log ref="log" :data="currentItem"></Log>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineAsyncComponent } from 'vue';
import { getActivity } from '@/api/operation/activity/index';
import { useRouter } from 'vue-router';
import common from '@/utils/common.ts';

export default {
  components: {
    Abstract: defineAsyncComponent(() => import('./abstract.vue')),
    Join: defineAsyncComponent(() => import('./join.vue')),
    Log: defineAsyncComponent(() => import('./log.vue'))
  },

  mounted() {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;
    this.proxy = proxy;

    const route = useRoute();
    this.currentItem.activityId = route.query.id;

    this.init();
  },
  data() {
    return {
      proxy: null,
      currentItem: JSON.parse(JSON.stringify(common.operActivity.defaultActivity))
    };
  },
  created() {},
  methods: {
    init() {
      let id = this.currentItem.activityId;
      this.get(id);
    },

    get(id) {
      getActivity(id).then((res) => {
        let data = res.data;
        let defaultItem = this.currentItem;
        data = common.operActivity.verifyDataIntegrity(defaultItem, data);
        this.currentItem = data;

        this.$nextTick(() => {
          this.$refs.abstract.init(data);
          this.$refs.join.init(data);
          this.$refs.log.init(data);
        });
      });
    },

    //返回
    handleCancel() {
      this.proxy?.$tab.closePage();
    }
  }
};
</script>

<style lang="scss"  scoped>
.info-container_header {
  background: white;

  .icon {
    width: 30px;
    height: 30px;
    fill: blank;
  }
}
</style>